** Clearing Stata memory
capture log close
clear all
set more off, perm
set seed 1234

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////// Table 6: Coefficient of Variation across Subjects  //////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 

 ** Opening Phase 2 norm_scores dataset 
use "Work Data/Gender_Phase2_long.dta",clear

* 1) Only years before the affirmative action took place
drop if aa_year==1
drop if year==2000
tab year

gen p2score_sd=score
gen p2score_mean=score
gen coef_var_p2score=score

gcollapse (cv) coef_var_p2score (mean) p2score_mean female wNPO norm_wNPO year norm_enem_w enem (sd) p2score_sd , by(inscri2)

gen int_fem_enem=norm_enem_w*female

** Label variables
label var female "Female"
label var norm_enem_w " Norm. ENEM scores"
label var int_fem_enem "Female $\times$ Norm. ENEM scores"

*** Coefficient of variation

estimates clear

reghdfe coef_var_p2score female ,  absorb(year) vce(robust)
estimates store reg1
estadd  ysumm
reghdfe coef_var_p2score female norm_enem_w,  absorb(year) vce(robust)
estimates store reg2
reghdfe coef_var_p2score female norm_enem_w int_fem_enem ,  absorb(year) vce(robust)
estimates store reg3

estadd local year_fe "Yes":  reg* 

* Tex
esttab  reg1 reg2 reg3  using "Output/Coef_variation_P2subjects.tex", se star(* 0.10 ** 0.05 *** 0.01) booktabs ///
stats(ymean ysd sepline N newline year_fe , fmt(%3.2fc %3.2fc %1s %9.0fc %1s %3s)  ///
labels( "Mean dependent variable" "Std.dev dependent variable" " " "Number of applicants" " " "Year dummies")) ///
 b(%7.3f) se(%7.3f)  replace f label nomtitle collabels(none) drop(_cons) nogap ///
 refcat(female " \\ \multicolumn{4}{l}{\textit{Dependent variable: Phase 2 score coefficient of variation}} \\", nolabel)


 